package com.group.library.order.util;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * @Author: Lai
 * @Describe: 时间工具类
 *              对localDate和LocalDateTime进行一些必要的格式转换
 */

public class TimeUtil {

    public static String parseDate2Str(LocalDateTime localDateTime){
        String dateStart = String.valueOf(localDateTime);
        String seconds = dateStart.substring(17, dateStart.length());
        int second = (int)Math.round(Double.parseDouble(seconds));
        dateStart = dateStart.substring(0,17)+String.valueOf(second);
        System.out.println("dateStart:"+dateStart);
        return dateStart;
    }

    //对LocalDate格式进行转化成常用的格式
    // 比如：2021-12-07 --> 2021年12月07日
    public static String parseDateAddYMR(LocalDate localDate){
        String[] date = String.valueOf(localDate).split("-");
        return date[0]+"年"+date[1]+"月"+date[2]+"日";

    }

}
